package com.htzos.admin.ac.controller;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.htzos.admin.ac.bean.AcFeedbackBase;
import com.htzos.admin.ac.service.AcFeedbackBaseService;
import com.htzos.admin.system.bean.SystemUserBase;
import com.htzos.base.parent.ctrl.BaseController;
import com.htzos.common.tool.ExtQueryBean;
import com.htzos.common.tool.TldTool;
import com.htzos.common.util.CommonUtil;

@Controller
@RequestMapping("/acFeedbackBase")
public class AcFeedbackBaseController extends BaseController{

    @Resource
    AcFeedbackBaseService acFeedbackBaseService;

    @RequestMapping("/list")
    public ModelAndView list(HttpServletRequest request,AcFeedbackBase condition, ExtQueryBean extQuery) {
        if(extQuery.getPageNum() == null) {
            extQuery.setSize(10);
            extQuery.setPageNum(1);
        }

        extQuery.setTotal(acFeedbackBaseService.acFeedbackBaseTotal(condition, extQuery));
        List<AcFeedbackBase> list= acFeedbackBaseService.acFeedbackBaseList(condition, extQuery);
        request.setAttribute("list", list);
        request.setAttribute("condition", condition);
        request.setAttribute("extQuery", extQuery);
        request.getSession(true).setAttribute("conditionStr", condition);
        request.getSession(true).setAttribute("extQueryStr", extQuery);
        return new ModelAndView("admin/ac/acFeedbackBaseList");
    }

    /**
     * 查询我的留言
     * @param request
     * @param condition
     * @param extQuery
     * @return
     */
    @RequestMapping("/listmine")
    public ModelAndView listmine(HttpServletRequest request,AcFeedbackBase condition, ExtQueryBean extQuery) {
        if(extQuery.getPageNum() == null) {
            extQuery.setSize(10);
            extQuery.setPageNum(1);
        }
        
        SystemUserBase user = (SystemUserBase) request.getSession().getAttribute(CommonUtil.CURRENTUSER);
        condition.setUserId(user.getId());
        condition.setUserName(user.getUserName());
        
        extQuery.setTotal(acFeedbackBaseService.acFeedbackBaseTotal(condition, extQuery));
        List<AcFeedbackBase> list= acFeedbackBaseService.acFeedbackBaseList(condition, extQuery);
        request.setAttribute("list", list);
        request.setAttribute("condition", condition);
        request.setAttribute("extQuery", extQuery);
        request.getSession(true).setAttribute("conditionStr", condition);
        request.getSession(true).setAttribute("extQueryStr", extQuery);
        return new ModelAndView("admin/ac/myFeedbackList");
    }
    
    
    
    @RequestMapping("/update")
    public ModelAndView update(HttpServletRequest request, AcFeedbackBase acFeedbackBase) {
        acFeedbackBaseService.acFeedbackBaseUpdate(acFeedbackBase);
        return new ModelAndView(new RedirectView("list"), getSessionQueryString(request));
    }
    
    @RequestMapping("/updateReadStatus")
    public ModelAndView updateReadStatus(HttpServletRequest request,HttpServletResponse response) {
    	AcFeedbackBase acFeedbackBase=new AcFeedbackBase();
    	Integer id=Integer.parseInt(request.getParameter("id"));
    	Integer readStatus=Integer.parseInt(request.getParameter("readStatus"));
    	acFeedbackBase.setId(id);
    	acFeedbackBase.setReadStatus(readStatus);
        acFeedbackBaseService.acFeedbackBaseUpdate(acFeedbackBase);
        return new ModelAndView(new RedirectView("list"), getSessionQueryString(request));
    }
    

    @RequestMapping("/updatePage")
    public String updatePage(HttpServletRequest request, String id) {
        AcFeedbackBase acFeedbackBase = acFeedbackBaseService.acFeedbackBaseGet(id);
        request.setAttribute("acFeedbackBase", acFeedbackBase);
        return "admin/ac/acFeedbackBaseUpdate";
    }

    @RequestMapping("/detail")
    public String detail(HttpServletRequest request, String id) {
        AcFeedbackBase acFeedbackBase = acFeedbackBaseService.acFeedbackBaseGet(id);
        request.setAttribute("acFeedbackBase", acFeedbackBase);
        return "admin/ac/acFeedbackBaseDetail";
    }

    @RequestMapping("/insert")
    public ModelAndView insert(HttpServletRequest request, AcFeedbackBase acFeedbackBase) {
    	SystemUserBase user = (SystemUserBase) request.getSession().getAttribute(CommonUtil.CURRENTUSER);
    	acFeedbackBase.setUserId(user.getId());
    	acFeedbackBase.setUserName(user.getUserName());
    	acFeedbackBase.setStatus(TldTool.STATUS_USE);
    	acFeedbackBase.setReadStatus(0);
        acFeedbackBaseService.acFeedbackBaseInsert(acFeedbackBase);
        return new ModelAndView(new RedirectView("listmine"), getSessionQueryString(request));
    }
    @RequestMapping("/addPage")
    public String addPage() {
        return "admin/ac/acFeedbackBaseAdd";
    }

    @RequestMapping("/delete")
    public ModelAndView delete(HttpServletRequest request, AcFeedbackBase acFeedbackBase) {
        acFeedbackBaseService.acFeedbackBaseDelete(acFeedbackBase);
         return new ModelAndView(new RedirectView("list"), getSessionQueryString(request));
    }
}